﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SuperRyoninRPG.Display;
using SuperRyoninRPG.Main;

namespace SuperRyoninRPG.Characters.Items
{
	public class Item:Thing
	{
		private Animation animation;
		private const string FolderPath = "Images/Items";

		private float appearVelocity = 50.0f;
		private float appearPosition;

		protected bool IsAppearing {
			get { return this.appearPosition != 0; }
		}

		public Item(Stage stage, Vector2 position, int frameWidth,string name)
			: base(stage, position, frameWidth)
		{
			this.Position = position;
			LoadContent(name);
			this.appearPosition = this.FrameWidth;
			this.Shift.Y = appearPosition;
			this.Direction = FaceDirection.Right;
			this.AllowTurnImage = false;
		}

		private void LoadContent(string name)
		{
			string path = Path.Combine(FolderPath, name);
			var texture = this.Stage.Content.Load<Texture2D>(path);
			animation = new Animation(texture, this.FrameWidth, 0.1f, true);
			this.Sprite.PlayAnimation(animation);
		}
		public override Animation Animation
		{
			get { return animation; }
		}

		protected override void GetInput(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyboardState, Microsoft.Xna.Framework.Input.GamePadState gamePadState, Microsoft.Xna.Framework.Input.Touch.TouchCollection touchState, Controller.AccelerometerState accelState, Microsoft.Xna.Framework.DisplayOrientation orientation)
		{
			
		}

		protected override void OnUpdate(GameTime gameTime)
		{
			base.OnUpdate(gameTime);

			if (this.appearPosition == 0)
			{
				return;
			}

			var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
			var appear = elapsed * this.appearVelocity;
			this.appearPosition -= appear;
			if (this.appearPosition <0)
			{
				this.appearPosition = 0;
			}
			this.Shift.Y = this.appearPosition;
		}

	}
}
